<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,maximum-scale=1.0" />
    <title>api接口测试</title>
    ${r"<#"}include "/view/admin/head.html"/>
    <script type="text/javascript" src="${r"${base}"}/jstool/jquery.form.js"></script>
<#if hasFile==1>
    <script type="text/javascript" src="${r"${base}"}/jstool/bootstrap-fileinput/js/fileinput.js"></script>
    <script type="text/javascript" src="${r"${base}"}/jstool/bootstrap-fileinput/js/locals/zh.js"></script>
    <link rel="stylesheet" type="text/css" href="${r"${base}"}/jstool/bootstrap-fileinput/css/fileinput.min.css" />
</#if>
<#if hasSwitch==1>
    <script type="text/javascript" src="${r"${base}"}/jstool/bootstrap-switch/bootstrap-switch.min.js"></script>
    <link rel="stylesheet" type="text/css" href="${r"${base}"}/jstool/bootstrap-switch/bootstrap-switch.min.css" />
</#if>
<#if hasDate==1>
    <script type="text/javascript" src="${r"${base}"}/jstool/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="${r"${base}"}/jstool/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
    <link rel="stylesheet" type="text/css" href="${r"${base}"}/jstool/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" />
</#if>
<#if hasSelect==1>
    <script type="text/javascript" src="${r"${base}"}/jstool/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="${r"${base}"}/jstool/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
    <link rel="stylesheet" type="text/css" href="${r"${base}"}/jstool/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" />
</#if>


    <script type="text/javascript" src="${r"${base}"}/jstool/bootstrap-validator-0.5.3/js/bootstrapValidator.min.js"></script>
    <script type="text/javascript" src="${r"${base}"}/jstool/bootstrap-validator-0.5.3/lang/zh_CN.min.js"></script>
    <link rel="stylesheet" type="text/css" href="${r"${base}"}/jstool/bootstrap-validator-0.5.3/css/bootstrapValidator.min.css" />


    <style type="text/css">
        .list-path {
            height: 50px;
            line-height: 50px;
            background-color: #9acfea;
        }

        .table-class {
            width: 90%;
            text-align: center;
            border: 1px solid #afd9ee;
            margin: 0 auto;
            margin-top: 50px;
        }

        table th {
            width: 20%;
            background-color: #d9edf7;
            text-align: right;
        }

        table td {
            width: 20%;
            text-align: left;
        }


    </style>
    <script type="text/javascript">

        $(function(){
            //初始化
        <#list columnList as var>
            <#if 'file'==var.inputType>
                $('#${var.properties}').fileinput({
                    language: 'zh', //设置语言
                    allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀
                    showUpload: false, //是否显示上传按钮
                    showCaption: false,//是否显示标题
                    browseClass: "btn btn-primary", //按钮样式
                    previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
                });
            <#elseif 'date'==var.inputType>
                $('#${var.properties}Start').datetimepicker({language: 'zh-CN' });
                $('#${var.properties}End').datetimepicker({language: 'zh-CN' });
            <#elseif 'switch'==var.inputType>
                <#list listSwitch as s>
                    <#if s.name==var.properties>
                    $('[name="${var.properties}cb"]').bootstrapSwitch({
                        <#list s.switch as st>
                            <#if st.value==1>
                                onText:"${st.name}",
                            <#elseif st.value==0>
                                offText:"${st.name}",
                            </#if>
                        </#list>
                        onColor:"success",
                        offColor:"info",
                        size:"small",
                        onSwitchChange:function(event,state){
                            if(state==true){
                                $(this).val("1");
                                $('[name="${var.properties}"]').val("1");
                            }else{
                                $(this).val("0");
                                $('[name="${var.properties}"]').val("0");
                            }
                        }
                    });
                    </#if>
                </#list>
            <#else>

            </#if>
        </#list>





        });

    </script>
</head>
<body>

<div class="list-path">
		<span style="margin-left: 50px;"> <a
                href="${r"${base}"}/${simpleClassname}/list.do"><span
                class="glyphicon glyphicon-home"></span> ${describe}列表</a> / ${describe}接口测试
		</span>
    <div style="float: right; margin-right: 40px;">
        <a class="btn btn-info"
           href="javascript:window.history.go(-1)">返回</a>
    </div>
</div>


<div class="table-class">
    ${r"<#"}include "/view/admin/opermsg.html"/>
        <form id="${simpleClassname}Form" action="#"
        <#if hasFile==1> method="post" enctype="multipart/form-data" </#if> >

            <table class="table table-bordered">
            <#assign num1=0>
            <#list columnList as var>


                <#if 'text'==var.inputType||'int'==var.inputType||'decimal'==var.inputType||'hidden'==var.inputType>
                    <#if num1%2==0><tr></#if>
                    <th>${var.describe}</th>
                    <td>
                        <div class="form-group">
                            <input type="text" class="form-control" id="${var.properties}" name="${var.properties}" placeholder="请输入${var.describe}" value="${r"${"}entity.${var.properties}!${r"}"}">
                        </div>
                    </td>
                    <#if (num1-1)%2==0||(var_index+1)==columnList?size></tr></#if>
                    <#assign num1=num1+1>
                <#elseif 'file'==var.inputType>
                    <#if num1%2==0><tr></#if>
                    <th>${var.describe}</th>
                    <td>
                    ${r"<#"}if entity.${var.properties}??>
                        <img src="${r"${base}${"}entity.${var.properties}!${r"}"}" height="100px">
                    ${r"</#"}if>

                        <input type="file" class="form-control" id="${var.properties}" name="file${var.propertiesUp}" >
                    </td>
                    <#if (num1-1)%2==0||(var_index+1)==columnList?size></tr></#if>
                    <#assign num1=num1+1>
                <#elseif 'date'==var.inputType>
                    <#if num1%2==0><tr></#if>
                    <th>${var.describe}开始时间</th>
                    <td>
                        <input type="text" class="form-control" value="${r"<#if "}(entity.${var.properties}Start)?? >${r"${"}entity.${var.properties}Start?string('yyyy-MM-dd HH:mm:ss')${r"}</#if>"}" id="${var.properties}Start" name="${var.properties}Start" data-date-format="yyyy-mm-dd hh:ii:ss">
                    </td>
                    <#if (num1-1)%2==0||(var_index+1)==columnList?size></tr></#if>
                    <#assign num1=num1+1>

                    <#if num1%2==0><tr></#if>
                    <th>${var.describe}结束时间</th>
                    <td>
                        <input type="text" class="form-control" value="${r"<#if "}(entity.${var.properties}End)?? >${r"${"}entity.${var.properties}End?string('yyyy-MM-dd HH:mm:ss')${r"}</#if>"}" id="${var.properties}End" name="${var.properties}End" data-date-format="yyyy-mm-dd hh:ii:ss">
                    </td>
                    <#if (num1-1)%2==0||(var_index+1)==columnList?size></tr></#if>
                    <#assign num1=num1+1>
                <#elseif 'switch'==var.inputType>
                    <#if num1%2==0><tr></#if>
                    <th>${var.describe}</th>
                    <td>
                        <input name="${var.properties}" type="hidden" value="${r"<#if"} entity.${var.properties}??>${r"${"}entity.${var.properties}${r"}<#else>0</#if>"}"/>
                        <input name="${var.properties}cb" type="checkbox"  data-size="small"
                               ${r"<#"}if entity.${var.properties}??>
                        <#list listSwitch as s>
                            <#if s.name==var.properties>
                                <#list s.switch as st>
                                ${r"<#"}if ${st.value}==entity.${var.properties}>
                                    <#if st.value==1>
                                        checked="checked"
                                    </#if>
                                    value="${st.value}"${r"</#"}if>
                                </#list>
                            </#if>
                        </#list>
                    ${r"</#"}if>/>
                    </td>
                    <#if (num1-1)%2==0||(var_index+1)==columnList?size></tr></#if>
                    <#assign num1=num1+1>


                <#elseif 'select'==var.inputType>
                    <#if num1%2==0><tr></#if>
                    <th>${var.describe}</th>
                    <td>
                        <div class="form-group">
                            <select id="${var.properties}" name="${var.properties}"
                                <#if 'int'==var.inputCode||'str'==var.inputCode>
                                    class="form-control selectpicker"   data-live-search="true"
                                <#else>
                                    class="form-control"
                                </#if>
                            >
                                <option value="">请选择${var.describe}</option>
                                <#list listSelect as s>
                                    <#if s.name==var.properties>
                                        <#if 'int'==var.inputCode || 'str'==var.inputCode>
                                        ${r"<#list"} list${var.propertiesUp} as lv>
                                            <option value="${r"${"}lv.value!${r"}"}"
                                            ${r"<#if"} lv.value??&&entity.${var.properties}??&&entity.${var.properties} == lv.value >
                                                selected="selected"
                                            ${r"</#if>"}
                                                >${r"${"}lv.name!${r"}"}</option>
                                        ${r"</#list>"}
                                        <#else>
                                            <#list s.select as st>
                                                <option value="${st.value}" ${r"<#"}if entity.${var.properties}??&&${st.value} == entity.${var.properties}>selected="selected"${r"</#"}if>>${st.name}</option>

                                            </#list>
                                        </#if>

                                    </#if>
                                </#list>
                            </select>
                        </div>
                    </td>
                    <#if (num1-1)%2==0||(var_index+1)==columnList?size></tr></#if>
                    <#assign num1=num1+1>
                </#if>
            </#list>
        <tr>
            <td colspan="4" width="100%" style="text-align: left;">
                <a class="btn btn-success " href="javascript:apiList()" >获取${describe}列表接口</a>
                <span style="width: 20px;">&nbsp;</span>
                <a class="btn btn-success " href="javascript:apiDetail()" >获取${describe}详情接口</a>


            </td>
        </tr>
        <tr>
            <td colspan="4" width="100%" style="text-align: center;height: 400px;" >
                  <pre>
链接：<code  id="url"></code>
                </pre>
                <pre>
返回结果集：<code  id="output"></code>
                </pre>
            </td>
        </tr>
    </table>
        </form>



</div>

<script type="text/javascript">
    function apiList(){

        var options = {
            target:        '#output',   // target element(s) to be updated with server response
            beforeSubmit:  showRequest,  // pre-submit callback
            success:       showResponse,  // post-submit callback

            // other available options:
            url:       "${r"${base}"}/${simpleClassname}/apiList.jn",         // override for form's 'action' attribute
            type:      "post",        // 'get' or 'post', override for form's 'method' attribute
            dataType:  "json"        // 'xml', 'script', or 'json' (expected server response type)
            //clearForm: true        // clear all form fields after successful submit
            //resetForm: true        // reset the form after successful submit

            // $.ajax options can be used here too, for example:
            //timeout:   3000
        };

        // 将myForm使用 'ajaxForm' 进行绑定
        $('#czjcommentsForm').ajaxForm(options);
        $('#url').text(options.url);
        $('#czjcommentsForm').submit();

    }
    function apiDetail(){
        var options = {
            target:        '#output',   // target element(s) to be updated with server response
            beforeSubmit:  showRequest,  // pre-submit callback
            success:       showResponse,  // post-submit callback

            // other available options:
            url:       '${r"${base}"}/${simpleClassname}/apiDetail.jn',         // override for form's 'action' attribute
            type:      "post",        // 'get' or 'post', override for form's 'method' attribute
            dataType:  "json"        // 'xml', 'script', or 'json' (expected server response type)
            //clearForm: true        // clear all form fields after successful submit
            //resetForm: true        // reset the form after successful submit

            // $.ajax options can be used here too, for example:
            //timeout:   3000
        };

        // 将myForm使用 'ajaxForm' 进行绑定
        $('#${simpleClassname}Form').ajaxForm(options);
        $('#url').text(options.url);
        $('#${simpleClassname}Form').submit();
    }
    function showRequest(formData, jqForm, options) {
        return true;
    }

    function showResponse(responseText, statusText, xhr, $form)  {

        $('#output').text(jsonFormat(JSON.stringify(responseText)));
    }
    function jsonFormat(jsonStr){
        var res="";
        for(var i=0,j=0,k=0,ii,ele;i<jsonStr.length;i++)
        {//k:缩进，j:""个数
            ele=jsonStr.charAt(i);
            if(j%2==0&&ele=="}")
            {
                k--;
                for(ii=0;ii<k;ii++) ele="    "+ele;
                ele="\n"+ele;
            }
            else if(j%2==0&&ele=="{")
            {
                ele+="\n";
                k++;
                for(ii=0;ii<k;ii++) ele+="    ";
            }
            else if(j%2==0&&ele==",")
            {
                ele+="\n";
                for(ii=0;ii<k;ii++) ele+="    ";
            }
            else if(ele=="\"") j++;
            res+=ele;
        }
        return res;
    }


</script>


</body>
</html>
